home *** CD-ROM | disk | FTP | other *** search
- /* ============
- * PedPaneTE.cc
- * ============
- */
-
- #include "PedestalDebugging.h"
-
- #include <Fonts.h>
- #include <TextEdit.h>
- #include <Windows.h>
-
- #include "PedPaneTE.hh"
-
- #include "Ped1AppProcess.hh"
- #include "PedApplication.hh"
- #include "PedView.hh"
-
- PedPaneTE::PedPaneTE(PedView &inSuperView)
- : PedPane(inSuperView), macTE(NULL)
- {
- }
-
- PedPaneTE::~PedPaneTE()
- {
- }
-
- void
- PedPaneTE::GetBounds(Rect &outBounds)
- {
- outBounds = mBounds;
- if (macTE) {
- short textHeight;
- textHeight = (*macTE)->nLines * (*macTE)->lineHeight;
- outBounds.bottom = outBounds.top + 4 + textHeight + 4;
- }
- }
-
- // FIXME: This is redundant
- void
- PedPaneTE::SetBounds(const Rect &inBounds)
- {
- mBounds = inBounds;
- }
-
- void
- PedPaneTE::GetScrollPos(Point &outPos)
- {
- if (macTE) {
- outPos.h = (*macTE)->viewRect.left - (*macTE)->destRect.left;
- outPos.v = (*macTE)->viewRect.top - (*macTE)->destRect.top;
- } else {
- ::SetPt(&outPos, 0, 0);
- }
- }
-
-
- enum {kPedMsgNone, kPedMsgScroll, kPedMsgNotifyScrolledTo};
-
- void
- PedPaneTE::NotifyIfScrolled(Point inOldPos)
- {
- Point newPos;
-
- GetScrollPos(newPos);
- if (inOldPos.v != newPos.v || inOldPos.h != newPos.h) {
- mSuperView.Message(kPedMsgNotifyScrolledTo, &newPos);
- }
- }
-
-
- void
- PedPaneTE::Init()
- {
- }
-
- void
- PedPaneTE::Open()
- {
- Rect textRect;
-
- PedPane::Open();
-
- if (macTE) return;
-
- //::SetPort(macWindow);
- ::TextFont(kFontIDMonaco);
- ::TextSize(9);
- //mSuperView.GetFrame(textRect);
- textRect = mBounds;
- ::InsetRect(&textRect, 4, 4);
- macTE = ::TENew(&textRect, &textRect);
- if (!macTE) throw;
- ::TEAutoView(true, macTE); // enable auto-scrolling
- }
-
- void
- PedPaneTE::Close()
- {
- if (macTE) {
- ::TEDispose(macTE);
- macTE = NULL;
- }
-
- PedPane::Close();
- }
-
- void
- PedPaneTE::Activate()
- {
- if (macTE)
- ::TEActivate(macTE);
-
- }
-
- void
- PedPaneTE::Deactivate()
- {
- if (macTE)
- ::TEDeactivate(macTE);
- }
-
- void
- PedPaneTE::Resize(short inWidth, short inHeight)
- {
- PedPane::Resize(inWidth, inHeight);
-
- if (!macTE) return;
-
- Point offset;
- mSuperView.GetWindowToLocalOffset(offset);
-
- Rect textRect = mBounds;
- ::InsetRect(&textRect, 4, 4);
- ::OffsetRect(&textRect, offset.h, offset.v);
- (*macTE)->destRect = textRect;
- textRect = mAperture;
- ::InsetRect(&textRect, 4, 4);
- (*macTE)->viewRect = textRect;
- ::TECalText(macTE);
- ::InvalRect(&mBounds);
- }
-
- void
- PedPaneTE::Scroll(short inH, short inV, bool inUpdate)
- {
- // FIXME
- ::TEPinScroll(-inH, -inV, macTE);
- }
-
- void
- PedPaneTE::Draw()
- {
- if (!macTE) return;
-
- Rect frame;
- mSuperView.GetFrame(frame);
-
- ::EraseRect(&frame);
- ::TEUpdate(&frame, macTE);
- }
-
- void
- PedPaneTE::DispatchNullEvent(EventRecord &inEvent)
- {
- ::GlobalToLocal(&inEvent.where);
- if (::PtInRect(inEvent.where, &mBounds)) {
- CursHandle cursIBeam = ::GetCursor(iBeamCursor);
- ThrowIfNULL_(cursIBeam);
- ::SetCursor(*cursIBeam);
- } else
- ::SetCursor(&qd.arrow);
- if (macTE)
- ::TEIdle(macTE);
- }
-
-
- void
- PedPaneTE::DispatchClickEvent(EventRecord &inEvent)
- {
- if (macTE == NULL)
- return;
-
- Point oldPos;
- GetScrollPos(oldPos);
-
- //::SetPort(macWindow);
- ::GlobalToLocal(&inEvent.where);
- ::TEClick(inEvent.where, inEvent.modifiers & shiftKey != 0, macTE);
-
- NotifyIfScrolled(oldPos);
- }
-
- void
- PedPaneTE::DispatchKey(EventRecord &inEvent)
- {
- // if (mResponder) {
- // char c = inEvent.message & charCodeMask;
- // short code = (inEvent.message & keyCodeMask) >> 8;
- // mResponder->RespondToKey(c, code);
- // }
- }
-
- void
- PedPaneTE::DoKey(char inChar)
- {
- if (macTE) {
- switch (inChar) {
- case '\x00':
- break;
- default:
- break;
- }
-
- Point oldPos;
- GetScrollPos(oldPos);
-
- ::TEKey(inChar, macTE);
-
- NotifyIfScrolled(oldPos);
- }
- }
-
- void
- PedPaneTE::GetSelection(long *inStart, long *inEnd)
- {
- if (!macTE) {*inStart = *inEnd = 0; return;}
-
- *inStart = (*macTE)->selStart;
- *inEnd = (*macTE)->selEnd;
- }
-
- void
- PedPaneTE::SetSelection(short inStart, short inEnd)
- {
- if (!macTE) return;
-
- Point oldPos;
- GetScrollPos(oldPos);
-
- ::TESetSelect(inStart, inEnd, macTE);
-
- NotifyIfScrolled(oldPos);
- }
-
- long
- PedPaneTE::AppendChars(char *buffer, long n)
- {
- if (!macTE) return 0;
-
- ::SetHandleSize((*macTE)->hText, (*macTE)->teLength + n);
- ThrowIfOSErr_(::MemError());
- ::BlockMoveData(buffer, *(*macTE)->hText + (*macTE)->teLength, n);
- (*macTE)->teLength += n;
- ::TECalText(macTE);
- mSuperView.Refresh();
-
- // We don't call NotifyIfScrolled() because we don't scroll at all.
- // Our caller may call SetSelection() afterward, though,
- // which case is handled already.
-
- return n;
- }
-
- void
- PedPaneTE::Cut()
- {
- if (macTE)
- ::TECut(macTE);
- }
-
- void
- PedPaneTE::Copy()
- {
- if (macTE)
- ::TECopy(macTE);
- }
-
- void
- PedPaneTE::Paste()
- {
- if (macTE)
- ::TEPaste(macTE);
- }
-
- void
- PedPaneTE::Clear()
- {
- if (macTE)
- ::TEDelete(macTE);
- }
-